﻿//
// Copyright 2008-2011 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//

using System;

namespace YaTools.Yaml
{
    public sealed partial class Dump
    {
        public abstract partial class Presenter
        {
            public abstract partial class Yaml
            {
                public class Explicit : Yaml.Flow
                {
                    public override void WriteSeperation(Dump dump)
                    {
                        if (Match(dump, Pending.DocumentHeader, "%YAML 1.2", Pending.BreakBefore))
                        {
                            RawWriteLine(dump);
                            RawWrite(dump, "---");
                        }

                        Match(dump, Pending.KeyDelimiter,   ':', Pending.SpaceAfter);
                        Match(dump, Pending.ListDelimiter,  ',', Pending.BreakAfter);
                        Match(dump, Pending.BeginMapping,   '{', Pending.BreakAfter | Pending.IndentAfter);
                        Match(dump, Pending.EndMapping,     '}', Pending.BreakAfter);
                        Match(dump, Pending.BeginSequence,  '[', Pending.BreakAfter | Pending.IndentAfter);
                        Match(dump, Pending.EndSequence,    ']', Pending.BreakAfter);
                        
                        base.WriteSeperation(dump);

                        if (Match(dump, Pending.DocumentEnd, String.Empty))
                        {
                            RawWriteLine(dump);
                            RawWriteLine(dump, "...");
                        }

                    }

                    public override void PresentNull(Dump dump)
                    {
                        dump.Write('~');
                    }

                    public override void PresentScalar(Dump dump, string value, Tag tag)
                    {
                        dump.WriteDoubleQuoted(value);
                    }
                }
            }
        }
    }
}